package jude.java.money.batch;

import static jude.java.money.batch.Definition.*;

public class Parameter<T> {
	public final int TYPE;
	/** 应用的站点 */
	public final String[][] SITES;
	/** 站点类型对应的密钥 */
	public final String KEY;
	/** 服务端执行路径 */
	public final String PATH;
	/** 参数, 文件,sql等实际执行目标 */
	public final T PARAMS;
	
	/** 本地路径 */
	public final String BASE_PATH;
	/** 标记, 用于是否覆盖等 */
	public final int FLAG;
	
	protected Parameter(Config c, T params) {
		this(c, params, 0);
	}
	
	protected Parameter(Config c, T params, int flag) {
		this.TYPE = c.getType();
		this.BASE_PATH = c.getBasePath();
		this.SITES = c.getSites();
		this.KEY = c.getKey();
		this.PATH = c.getPath();
		this.PARAMS = params;
		this.FLAG = flag;
	}
	
	protected Parameter(String basePath, String[][] sites, String key, String path, T params, int flag) {
		this.TYPE = 0;
		this.BASE_PATH = basePath;
		this.SITES = sites;
		this.KEY = key;
		this.PATH = path;
		this.PARAMS = params;
		this.FLAG = flag;
	}
	
	protected Parameter(int type, T params) {
		this(type, params, 0);
	}
	protected Parameter(int type, T params, int f) {
		switch (type) {
		case TYPE_ZENCART:
			this.BASE_PATH = Config.Zencart.BASE_PATH;
			this.SITES = Config.Zencart.SITES;
			this.KEY = Config.Zencart.KEY;
			this.PATH = Config.Zencart.PATH;
			break;
		case TYPE_WORDPRESS:
			this.BASE_PATH = Config.Wordpress.BASE_PATH;
			this.SITES = Config.Wordpress.SITES;
			this.KEY = Config.Wordpress.KEY;
			this.PATH = Config.Wordpress.PATH;
			break;
		case TYPE_MAGENTO:
			this.BASE_PATH = Config.Magento.BASE_PATH;
			this.SITES = Config.Magento.SITES;
			this.KEY = Config.Magento.KEY;
			this.PATH = Config.Magento.PATH;
			break;
		default:
			this.BASE_PATH = null;
			this.SITES = null;
			this.KEY = null;
			this.PATH = null;
			break;
		}
		this.TYPE = type;
		this.PARAMS = params;
		this.FLAG = f;
	}
	
	protected Parameter(String basePath, String[][] sites, String key, String path, T params) {
		this(basePath, sites, key, path, params, 0);
	}
	
	public static <F> Parameter<F> get(int type, F params) {
		return new Parameter<F>(type, params);
	}
	
	public static <F> Parameter<F> zencart(F params) {
		return new Parameter<F>(Definition.TYPE_ZENCART, params);
	}
	
	public static <F> Parameter<F> magento(F params) {
		return new Parameter<F>(Definition.TYPE_MAGENTO, params);
	}
	
	public static <F> Parameter<F> wordpress(F params) {
		return new Parameter<F>(Definition.TYPE_WORDPRESS, params);
	}
	
	public static <F> Parameter<F> zencart(F params, int f) {
		return new Parameter<F>(Definition.TYPE_ZENCART, params, f);
	}
	
	public static <F> Parameter<F> magento(F params, int f) {
		return new Parameter<F>(Definition.TYPE_MAGENTO, params, f);
	}
	
	public static <F> Parameter<F> wordpress(F params, int f) {
		return new Parameter<F>(Definition.TYPE_WORDPRESS, params, f);
	}
}
